<?php

use Dcat\Admin\Admin;
use Dcat\Admin\Grid;
use Dcat\Admin\Form;
use Dcat\Admin\Grid\Filter;
use Dcat\Admin\Show;
use Dcat\Admin\Layout\Menu;
use Dcat\Admin\Layout\Navbar;


/**
 * Dcat-admin - admin builder based on Laravel.
 * @author jqh <https://github.com/jqhph>
 *
 * Bootstraper for Admin.
 *
 * Here you can remove builtin form field:
 *
 * extend custom field:
 * Dcat\Admin\Form::extend('php', PHPEditor::class);
 * Dcat\Admin\Grid\Column::extend('php', PHPEditor::class);
 * Dcat\Admin\Grid\Filter::extend('php', PHPEditor::class);
 *
 * Or require js and css assets:
 * Admin::css('/packages/prettydocs/css/styles.css');
 * Admin::js('/packages/prettydocs/js/main.js');
 *
 */

// 覆盖默认配置
config(['admin' => user_admin_config()]);
config(['app.locale' => config('admin.lang') ?: config('app.locale')]);

// 菜单定义
Admin::menu(function (Menu $menu) {
    // 用户与权限
    $menu->add([
        [
            'id' => '1', // 此id只要保证当前的数组中是唯一的即可
            'title' => '用户与权限',
            'icon' => 'feather icon-users',
            'uri' => '',
            'parent_id' => 0,
            'permission_id' => '', // 与权限绑定
            'roles' => '', // 与角色绑定
        ],
        [
            'id' => '2', // 此id只要保证当前的数组中是唯一的即可
            'title' => '用户',
            'icon' => 'feather icon-circle',
            'uri' => 'user',
            'parent_id' => '1',
        ],
        [
            'id' => '3', // 此id只要保证当前的数组中是唯一的即可
            'title' => '角色',
            'icon' => 'feather icon-circle',
            'uri' => 'role',
            'parent_id' => '1',
        ],
        [
            'id' => '4', // 此id只要保证当前的数组中是唯一的即可
            'title' => '权限',
            'icon' => 'feather icon-circle',
            'uri' => 'permission',
            'parent_id' => '1',
        ],
    ]);
    // 内容管理
    $menu->add([
        [
            'id' => 'topic_manage', // 此id只要保证当前的数组中是唯一的即可
            'title' => '内容管理',
            'icon' => 'fa-file-text-o',
            'uri' => '',
            'parent_id' => 0,
            'permission_id' => '', // 与权限绑定
            'roles' => '', // 与角色绑定
        ],
        [
            'id' => 'topic', // 此id只要保证当前的数组中是唯一的即可
            'title' => '话题',
            'icon' => 'feather icon-circle',
            'uri' => 'topic',
            'parent_id' => 'topic_manage',
        ],
        [
            'id' => 'reply', // 此id只要保证当前的数组中是唯一的即可
            'title' => '回复',
            'icon' => 'feather icon-circle',
            'uri' => 'reply',
            'parent_id' => 'topic_manage',
        ],
        [
            'id' => 'category', // 此id只要保证当前的数组中是唯一的即可
            'title' => '分类',
            'icon' => 'feather icon-circle',
            'uri' => 'category',
            'parent_id' => 'topic_manage',
        ],
        [
            'id' => '5', // 此id只要保证当前的数组中是唯一的即可
            'title' => '标签',
            'icon' => 'feather icon-circle',
            'uri' => 'tag',
            'parent_id' => 'topic_manage',
        ],
    ]);
    // 站点管理
    $menu->add([
        [
            'id' => '1', // 此id只要保证当前的数组中是唯一的即可
            'title' => '站点管理',
            'icon' => 'fa-gears',
            'uri' => '',
            'parent_id' => 0,
            'permission_id' => '', // 与权限绑定
            'roles' => '', // 与角色绑定
        ],
        [
            'id' => '2', // 此id只要保证当前的数组中是唯一的即可
            'title' => '站点设置',
            'icon' => 'feather icon-circle',
            'uri' => 'setting/config',
            'parent_id' => '1',
        ],
        [
            'id' => '3', // 此id只要保证当前的数组中是唯一的即可
            'title' => '推荐资源',
            'icon' => 'feather icon-circle',
            'uri' => 'link',
            'parent_id' => '1',
        ],

    ]);
});
// 自定义导航菜单
Admin::navbar(function (Navbar $navbar) {

    $method = config('admin.layout.horizontal_menu') ? 'left' : 'right';

    // ajax请求不执行
    if (!Dcat\Admin\Support\Helper::isAjaxRequest()) {
        // 前台首页
        $navbar->$method(App\Admin\Actions\OpenHome::make()->render());
        // 后台设置
        $navbar->$method(App\Admin\Actions\AdminSetting::make()->render());
        // 缓存设置
        // $navbar->$method(view('admin.navbar.cache'));
        $navbar->$method(App\Admin\Actions\CacheManage::make()->render());
    }
});

